/***************************************************************************
 *   Copyright (C) 2010 by Oleg Goncharov  *
 *   $EMAIL$                           *                          
 *                                                                         *
 *   This file is part of ChessVision.                                     *
 *                                                                         *
 *   ChessVision is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef CIMAGESOURCE_H
#define CIMAGESOURCE_H

#include <opencv/cv.h>

/**
Интерфейс для получения изображений.

	@author Goncharov Oleg <goncharovoi@yandex.ru>
*/

//TODO Rewrite in object-orinted style.
class CImageSource {
protected:
	IplImage * img, *grey;
	
	void Clear();
public:
	CImageSource() { img = 0; grey = 0; }
	virtual ~CImageSource();
	
	virtual IplImage * GrabFrame() = 0;
	
	CvSize Size() { return cvGetSize(Img()); }
	//TODO To make it work in this way was a really bad idea.
	IplImage * Img() { if (!img) img = GrabFrame(); return img;}
	IplImage * Grey() { 
		if (!grey) {
			grey = cvCreateImage(cvGetSize(Img()), IPL_DEPTH_8U, 1);
			cvCvtColor(img, grey, CV_BGR2GRAY);
		}
		return grey; 
	}
	
};

#endif
